package com.ruoyi.student.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.student.domain.SysRegistryTime;
import com.ruoyi.student.service.ISysRegistryTimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import jakarta.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 注册时间段配置Controller
 *
 * @author ruoyi-mate
 * @date 2025-08-29
 */
@RestController
@RequestMapping("/student/registryTime")
public class SysRegistryTimeController extends BaseController
{
    @Autowired
    private ISysRegistryTimeService sysRegistryTimeService;

    /**
     * 查询注册时间段配置列表
     */
//    @PreAuthorize("@ss.hasPermi('student:registryTime:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysRegistryTime sysRegistryTime)
    {
        startPage();
        List<SysRegistryTime> list = sysRegistryTimeService.selectSysRegistryTimeList(sysRegistryTime);
        return getDataTable(list);
    }

    /**
     * 导出注册时间段配置列表
     */
/*    @PreAuthorize("@ss.hasPermi('student:registryTime:export')")*/
    @Log(title = "注册时间段配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysRegistryTime sysRegistryTime)
    {
        List<SysRegistryTime> list = sysRegistryTimeService.selectSysRegistryTimeList(sysRegistryTime);
        ExcelUtil<SysRegistryTime> util = new ExcelUtil<SysRegistryTime>(SysRegistryTime.class);
        util.exportExcel(response, list, "注册时间段配置数据");
    }

    /**
     * 获取注册时间段配置详细信息
     */
/*    @PreAuthorize("@ss.hasPermi('student:registryTime:query')")*/
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysRegistryTimeService.selectSysRegistryTimeById(id));
    }

    /**
     * 获取当前生效的注册时间段
     */
    @GetMapping(value = "/current")
    public AjaxResult getCurrent()
    {
        return success(sysRegistryTimeService.selectLatestRegistryTime());
    }

    /**
     * 新增注册时间段配置
     */
/*    @PreAuthorize("@ss.hasPermi('student:registryTime:add')")*/
    @Log(title = "注册时间段配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysRegistryTime sysRegistryTime)
    {
        return toAjax(sysRegistryTimeService.insertSysRegistryTime(sysRegistryTime));
    }

    /**
     * 修改注册时间段配置
     */
/*    @PreAuthorize("@ss.hasPermi('student:registryTime:edit')")*/
    @Log(title = "注册时间段配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysRegistryTime sysRegistryTime)
    {
        return toAjax(sysRegistryTimeService.updateSysRegistryTime(sysRegistryTime));
    }

    /**
     * 删除注册时间段配置
     */
/*    @PreAuthorize("@ss.hasPermi('student:registryTime:remove')")*/
    @Log(title = "注册时间段配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysRegistryTimeService.deleteSysRegistryTimeByIds(ids));
    }
}
